package com.tarena.lbs.user.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.user.pojo.param.UserParam;
import com.tarena.lbs.user.pojo.param.UserTagsParam;
import com.tarena.lbs.user.pojo.po.UserPO;
import com.tarena.lbs.user.pojo.vo.UserVO;
import com.tarena.lbs.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;



/**
 * 手机小程序用户处理
 */
@Slf4j
@Api(tags = "用户接口")
@RestController
public class UserController {
    @Autowired
    private UserService userService;


    @ApiOperation(value = "用户查询")
    @PostMapping("/basic/user/list")
    public Result<List<UserVO>> list(@RequestBody UserParam param){
        log.info("用户查询：{}",param);
        List<UserVO> userVOList = userService.list(param);
        return new Result<>(userVOList);

    }

    @ApiOperation(value = "用户注册")
    //小程序新增注册
    @PostMapping("/basic/user/info/register")
    public Result<Void> register(@RequestBody UserParam param){
        log.debug("用户注册,{}", param);
        try {
            userService.register(param);
        } catch (BusinessException e) {
            throw new RuntimeException(e);
        }
        return Result.success();
    }

//    解析jwt 拿到id获取登录用户性情
    @ApiOperation(value = "用户详情")
    @PostMapping("/basic/user/detail/{userId}")
    public Result<UserVO> detail(@PathVariable Integer userId)throws BusinessException{
        return new Result<>(userService.detail(userId));
    }


    //用户提交绑定关联所选标签
    @ApiOperation(value = "用户标签关联")
    @GetMapping("/basic/user/tag")
    public Result<Void> bindUserTags(UserTagsParam param)
        throws BusinessException{
        log.debug("用户标签关联", param);
        userService.bindUserTags(param);
        return Result.success();
    }
}
